package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.ItemPowerUpdateTable;
import com.lineage.server.datatables.RecordTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ItemStatus;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1ItemPowerUpdate;

public class saveweaponG extends ItemExecutor {
  public static ItemExecutor get() {
    return new saveweaponG();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    int itemobj = data[0];
    L1ItemInstance item2 = pc.getInventory().getItem(itemobj);
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    L1ItemPowerUpdate info = ItemPowerUpdateTable.get().get(item2.getItemId());
    if (info == null) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    if (info.get_mode() == 4) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    if (tgItem != null) {
      if (tgItem.getItem().getItemId() <= -1) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
        return;
      } 
      if (tgItem.getproctect6()) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("目前该装备已经受到保护中"));
        return;
      } 
      tgItem.setproctect6(true);
      pc.sendPackets((ServerBasePacket)new S_ItemStatus(tgItem));
      pc.getInventory().saveItem(tgItem, 4);
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("保护卷轴的力量附着的物品中。"));
      pc.getInventory().removeItem(item, 1L);
      RecordTable.get().recordFailureArmor1(pc.getName(), item.getAllName(), tgItem.getAllName(), item.getId(), 
          "赋予升接保护", pc.getIp());
    } 
  }
}
